<template>
	<view class="content">
		<view class="title">充值金额</view>
		<view class="list">
			<view v-for="(item,index) in moneylist" @tap="selectprice(index,item)"
				:class="indexcss==index?'item select':'item'">
				<view class="num">{{item}}元</view>
				<view class="txt">售{{item}}元</view>
			</view>
			<view class="item">
				<u--input placeholder="请输入内容" border="none" v-model="value" @focus="clickother" @change="othermoney"
					placeholderStyle="color:#333" inputAlign="center"></u--input>
			</view>
			<div class="clear"></div>
		</view>
		<view class="chongzhi">
			<u-button type="primary" text="微信充值" icon="weixin-fill" color="#23BF61" size="large"
				@click="chongzhi"></u-button>
		</view>
	</view>
</template>

<script>
	let that
	import {
		mapState,
		mapActions
	} from 'vuex'
	export default {
		data() {
			return {
				moneylist: [10, 20, 50, 100, 200, 300],
				indexcss: -1,
				price: 0,
			}
		},
		mounted() {
			that = this
		},
		computed: {
			//引入store全局变量
			...mapState(['loginState', 'userInfo'])
		},
		methods: {
			//引入store全局方法
			...mapActions(['userLoginAction', 'userLogoutAction']),
			//点击自定义输入
			clickother() {
				this.indexcss = -1
			},
			//选中输入的价格
			selectprice(index, price) {
				this.indexcss = index
				this.price = price
			},
			othermoney: function(e) {
				this.price = e
			},
			chongzhi(){
				uni.showModal({
					title: '充值订单',
					content: '请确认是否充值'+this.price+'元到余额',
					success: function(res) {
						if (res.confirm) {
							that.$http_api.chongzhi({
								uid: that.userInfo.id,
								price:that.price
							}).then((res) => {
								if(res.code==2){
									that.userLoginAction(res.userinfo)
									setTimeout(function(){
										uni.switchTab({
											url:'/pages/wallet/wallet'
										})
									},2000)
								}
							})
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 100%;
		padding: 0 3%;
		box-sizing: border-box;
	}

	.title {
		font-size: 28rpx;
		padding: 40rpx 0;
	}

	.list .item {
		width: 30%;
		margin-right: 4.1%;
		float: left;
		border: 1px solid #23BF61;
		margin-bottom: 30rpx;
		height: 130rpx;
		text-align: center;
		font-size: 28rpx;
		padding-top: 20rpx;
		box-sizing: border-box;

		.num {
			color: #23BF61;
			font-size: 33rpx;
			font-weight: bold;
		}

		.txt {
			color: #666;
		}
	}

	.list .item.select {
		background-color: #23BF61;

		.num {
			color: #fff;
		}

		.txt {
			color: #fff;
		}
	}

	.list .item:nth-child(3n) {
		margin-right: 0;
	}

	.list .item:nth-child(7) {
		padding-top: 40rpx;
	}

	.input-placeholder {
		color: #666;
		font-size: 28rpx;
	}

	.chongzhi {
		position: fixed;
		bottom: 100rpx;
		width: 93%;
	}
</style>